// 客户管理
// ---------------------------------------------------------------------
isc.ListGrid.create({//内置分类列表(只显示未分类与所有分类)
	ID:"cusCategoryLista",cellHeight:35,height:70,border:0,
	leaveScrollbarGap:false,showHeader :false
   ,cellContextClick:"return cusCategoryListMenua.showContextMenu()"
   ,fields:[{name:"name",type:"text"}]
   ,data:[{name:"所有分类"},{name:"未分类"}]
   ,rowClick: function(record){
	   cusCategoryList.deselectAllRecords();
	   if(record.name == "所有分类") customerList.filterData();
	   else customerList.filterData({ fieldName:"category_pk", operator:"isNull" });
   }
});
isc.Menu.create({//内置分类右键菜单
	ID:"cusCategoryListMenua", cellHeight:32, cellWidth:60, 
	data:[{title:"新增",icon:"icon_add.png",click:"cusCategoryList.startEditingNew();"}]
});
isc.ListGrid.create({//自定义分类列表
	ID:"cusCategoryList",fetchOperation:"myFetch",dataSource:"customer_categoryDS",cellHeight:35,useAllDataSourceFields:true,
	leaveScrollbarGap:false, canEdit:true, showHeader:false, modalEditing:true, autoFetchData: true
	,cellContextClick:"return cusCategoryListMenu.showContextMenu()"
	,rowClick: "cusCategoryLista.deselectAllRecords(); if(record){  customerList.filterData({category_pk:record.pk}) }"
});
isc.Menu.create({//自定义分类右键菜单
	ID:"cusCategoryListMenu", cellHeight:22, data:[
        {title:"新增",icon:"icon_add.png",click:"cusCategoryList.startEditingNew();"},
        {isSeparator:true},
		{title:"编辑",icon:"icon_edit.png",click:"cusCategoryList.startEditing(cusCategoryList.getFocusRow());"},
		{title:"删除",icon:"icon_delete.png",click:'isc.confirm("确定要删除吗？","if(value)cusCategoryList.removeSelectedData()");'}
	]
});
isc.Window.create({//EXCEL导入窗口
    ID: "cusImportWindow", title: "客户导入",height:"100%", width: '800',autoCenter: true, isModal: true, showModalMask: true, autoDraw: false,
    closeClick : function () {
    	this.Super("closeClick", arguments);
    	cusCategoryList.invalidateCache();
    },
    items: [
		isc.BatchUploader.create({
			layoutMargin:15,partialCommitPrompt:"你的数据中有错误，所以不会被全部保存，如果您继续，有错误的记录将不会被导入。",
			uploadFormFields: [
			    { value: "customer.xls", title:"模板下载",canEdit: false, type: "link" ,width:180}
			],
            uploadDataSource: customerDS,uploadFileLabel:"Excel ",
            requestProperties:{willHandleError:true},
            gridProperties: {height:350,width: '100%'},
            gridFields :[
		        {name:"telephone"},{name:"truename"},{name:"sex"},{name:"address"},
		        {name:"company"},{name:"category"},{name:"remark"}
		        ]
        })
    ]
});
isc.ListGrid.create({//客户列表
	ID:"customerList",dataSource:"customerDS",fetchOperation:"userFetch",filterOnKeypress: true,
	useAllDataSourceFields:true,showRowNumbers:true,canEdit:true, modalEditing:true,
	autoFetchData: true, showFilterEditor: true, selectionAppearance:"checkbox", selectionType:"simple",
	dataArrived:function(startRow,endRow){
		//不是自己的不能编辑,分类不显示
		var data = this.data;
		for(var i = startRow; i< endRow; i++ ){
			if(data.get(i).user_pk != currUserPK){
				data.get(i).enabled=false;
				data.get(i).category_pk=null;
			}
		}
	},
	fields:[
	    {name:"category",hidden:true},
        {ID:"customerList_category",name:"category_pk",title:"分类",optionDataSource:"customer_categoryDS",optionOperationId:"myFetch",valueField:"pk",displayField:"name" ,editorType: "SelectItem"},
        {name:"remark"},
        {name:"lastSendDate",canEdit:false,width:100}
        /*
        ,{title:"操作",type:"any",width:60,canEdit:false
			,formatCellValue  :function (value){
				   return "<div style='text-decoration:underline;cursor:pointer'>通话记录</div>";
			 }
			,recordClick: function(viewer, record, recordNum, field, fieldNum, value, rawValue){
				callinList.filterData({customer_pk:record.pk})
				smartFormFieldsWin.show();
			}
        }
        */
	    ]
});
isc.Window.create({//显示字段窗口
	ID:"smartFormFieldsWin",title: "通话记录",height:"500",width:"500", autoCenter: true, isModal: true, 
    showModalMask: true, autoDraw: false,autoSize:false,
    items: [
				isc.ListGrid.create({//通话记录列表
					ID:"callinList",
					dataSource:"callinDS",fetchOperation:"customerFetch",
					useAllDataSourceFields:true,
					showRowNumbers:true,
					canEdit:true,
				    modalEditing:true,
					alternateRecordStyles:true,
				    autoFetchData: false,
				    showFilterEditor: true,
					filterOnKeypress: true
				})
            ]
});


isc.HLayout.create({
	 ID: "customerButtonLayout", autoDraw: false, layoutTopMargin: 3, membersMargin: 3, height:30,
    members: [
        isc.IButton.create({title: "增加人员", click:"customerList.startEditingNew()" }),
        isc.IButton.create({
            title: "删除选中人员",click: function () {
	    		 if (customerList.getSelectedRecord()) {
	    			 isc.confirm("确定要删除吗？","value?customerList.removeSelectedData():value");
	    		 }
	    	}
        }),
        isc.IButton.create({
        	title: "从EXCEL导入",click:"cusImportWindow.show()"
        })
    ]
});
isc.HLayout.create({
	ID:"userPageLayout",
	width:"100%",
	height:"100%",
	autoShow:false,
	members:[
		isc.SectionStack.create({
			width:180,
			showResizeBar:false,
			visibilityMode:"multiple",
            animateSections:true,
			cellHeight:22,
			sections:[
				{title:"客户分类", autoShow:true,cellAlign:'center', 
					items:[cusCategoryLista,cusCategoryList]}
			]
		}),
		isc.SectionStack.create({
			showResizeBar:false,
			visibilityMode:"multiple",
            animateSections:false,
			sections:[
				{title:"客户", autoShow:true, canCollapse: true,items:[customerButtonLayout,customerList]}
			]
		})
	]
});


//黑名单
//---------------------------------------------------------------------
isc.Window.create({
	ID: "blackWindow", title: "备选客户", width: '600', height: '400', autoCenter: true, isModal: true, showModalMask: true, autoDraw: false,
	items: [
			isc.ListGrid.create({//客户列表
				ID:"blackListSrc",dataSource:"customerDS",fetchOperation:"userFetch",filterOnKeypress: true,
				useAllDataSourceFields:true,showRowNumbers:true,canEdit:true, modalEditing:true,alternateRecordStyles:true,
				autoFetchData: true, showFilterEditor: true, selectionAppearance:"checkbox", selectionType:"simple",dragDataAction: "copy",
				fields:[
					    {name:"category",hidden:true},
				        {name:"category_pk",hidden:true}
				    ]
			}),
			isc.IButton.create({
				title: "确定", click:function(){
					var data = blackListSrc.getSelection();
					var wasQueuing = RPCManager.startQueue();
					for(var i = 0; i < data.length; i++){
						var d = data.get(i);
						blackList.addData(d,null,{willHandleError:true});
					}
					if (!wasQueuing) RPCManager.sendQueue(function(){
						blackWindow.hide();
					});
				}
			})
	]
});
isc.HLayout.create({membersMargin:10, height:'100%', width:"100%", ID:"blackApp",members:[
	    isc.SectionStack.create({width:'40%',sections:[{title:"黑名单",autoShow:true, items:[
	  		isc.HLayout.create({//黑名单操作按钮
	  			layoutTopMargin: 3,membersMargin:3,height:30,
				members: [
				    isc.IButton.create({title: "从客户中选择",click:"blackWindow.show();blackListSrc.deselectAllRecords();"}),
				    isc.IButton.create({title: "直接增加",click:"blackList.startEditingNew()"}),
				    isc.IButton.create({title: "删除选中",click:function(){
						 if (blackList.getSelectedRecord()) {
	 		    			 isc.confirm("确定要删除吗？","if(value)blackList.removeSelectedData()");
	 		    		 }else{
	 	    				 isc.say("请选择记录");
	 	    			 }
	 				}})
			    ]
			}),
			isc.ListGrid.create({//黑名单列表
				ID:"blackList",dataSource:"blackDS",addOperation:"userAdd",fetchOperation:"userFetch",useAllDataSourceFields:true,
				autoFetchData: true, showFilterEditor: true, canEdit: true, modalEditing:true,
			    selectionType:"simple",filterOnKeypress: true,preventDuplicates :true,selectionAppearance:"checkbox"
			})
	]}]})
]});

//短信发送
//---------------------------------------------------------------------
isc.Window.create({
	  ID: "smsWindow", title: "备选客户", width: '600', height: '400', autoCenter: true, immodal: true, showModalMask: true, autoDraw: false,
	  items: [
			isc.ListGrid.create({
				ID:"smSendListSrc",fetchOperation:"whiteFetch",dataSource:"customerDS",
				useAllDataSourceFields:true,alternateRecordStyles:true,autoFetchData: true,
			    showFilterEditor: true,selectionType:"simple",selectionAppearance:"checkbox",
				filterOnKeypress: true,dragDataAction: "copy",
				fields:[
				        {name:"category",hidden:true},
				        {name:"category_pk",optionDataSource:"customer_categoryDS",optionOperationId:"myFetch",valueField:"pk",displayField:"name" ,editorType: "SelectItem"}
			        ],
			    copyData:function(){
					  var ss = smSendListSrc.getSelection();
					  for(var i = 0; i < ss.length; i++){
						 var s = ss.get(i);
						 var record = {mt_dst_num:s.telephone,mt_dst_name:s.truename};
						 if(!smSendList.data.find("mt_dst_num",s.telephone)){
							 //只增加不重复的
							 smSendList.addData(record);
						 }
					  }
			    }
			}),
			 isc.IButton.create({
				    title: "确定", click:function(){
				    	smSendListSrc.copyData();
				    	smsWindow.hide();
				    }
			 })
	  ]
});
isc.Window.create({
    ID: "smsModelWindow",title: "短信模板", width: '600',height: '400',autoCenter: true,isModal: true,
    showModalMask: true, autoDraw: false,
    items: [
      	  isc.ListGrid.create({
      		dataSource:"sms_config",fetchOperation:"allFetch",useAllDataSourceFields:true,
      	    modalEditing:true,autoFetchData: true,wrapCells: true, width: '100%', height: '100%',cellHeight: 56,
      	    rowClick:function(record){
      	    	smTaskForm.getItem('mt_content').setValue(record.content);
      	    	smTaskForm.getItem('mt_dst_size').setValue(record.mt_dst_size);
      	    	smsModelWindow.hide();
      	    }
      	})
    ]
});
isc.HLayout.create({membersMargin:10, height:'100%', width:"100%", ID:"smSendApp",
	members:[
		isc.SectionStack.create({sections:[{title:"短信发送",autoShow:true, items:[
	      	 isc.HLayout.create({layoutTopMargin: 3,membersMargin: 3,height:30,
	 	  	      members: [
	 	  	          isc.IButton.create({title: "增加收件人",click:"smsWindow.show();smSendListSrc.deselectAllRecords();"}),
	 	  	          isc.IButton.create({title: "删除选中收件人",click: "smSendList.removeSelectedData();"})
	 	  	      ]
	      	 }),
	   	   	 isc.TileGrid.create({
				ID:"smSendList",selectionType:"simple", tileWidth:80,border:0,tileHeight:35,height:100,showEdges:false,border:1, data:[],
	   	   	    fields:[
						{name:"mt_dst_num"}, {name:"mt_dst_name"}
					]
	   	   	 }),
		     isc.IButton.create({
					title: "从模板中选择短信内容",width:150,
					click:'smsModelWindow.show()'
				 }),
		   	 isc.DynamicForm.create({
				ID: 'smTaskForm',width: '100%',titleAlign:"left",colWidths: [70, "*"],cellBorder:0,
				fields: [
					{name:"mt_content",type:"textArea",showTitle: false,colSpan:'4',width:"*",required:"true",
						changed: function(form, item, value){
							form.getItem('mt_dst_size').setValue(Math.ceil(value.length/70));
						}
					}, 
					{name:"mt_dst_size", type:"integer",title: "短信条数",width:"*",canEdit:false,defaultValue:0} ,
					{name:"sign", type:"text",title: "签名",width:"*",canEdit:false,defaultValue:currUserSmsSign} ,
					{name:"mt_at_time", type:"datetime",title: "发送时间",canEdit:true},
					{type:"button",title: "确定",width:'80'
						,click:function(){
							//将form中的数据设置到每条特发记录中
							var data = smSendList.data;
							if(data.length < 1){
								isc.warn("请选择收件人！");
								return;
							}
							if(!smTaskForm.validate()) return;
							
							var wasQueuing = RPCManager.startQueue();
							for(var i = 0; i < data.length; i++){
								var d = data.get(i);
								d.mt_content=smTaskForm.getValue('mt_content');
								d.mt_at_time=smTaskForm.getValue('mt_at_time');
								sms_task.addData(d,null,{willHandleError:true});
							}
							if (!wasQueuing) RPCManager.sendQueue(function(responses){
//								debugger;
								smSendList.setData([]);
								var errorMsg = " ";
								for(var i = 0;  i <  responses.getLength(); i++){
									var res = responses.get(i);
									if(res.status == -1){
										errorMsg += res.data+" ";
									}
								}
								if(errorMsg == " "){
									isc.say("已保存到待发列表中！");
								}else{
									isc.warn("短信条数超出配额限制，以下短信未能发送"+errorMsg);
								}
							});
						}
					}
				]
			})
	]}]})
		
]});



//待发列表
//---------------------------------------------------------------------
isc.SectionStack.create({ID:"willSendApp",width:'100%',sections:[{title:"待发送短信管理",autoShow:true, items:[
	isc.HLayout.create({//操作按钮
		layoutMargin: 3,height:30,
		members: [
		    isc.IButton.create({title: "删除选中",click:function(){
				 if (smsTaskList.getSelectedRecord()) {
		    			 isc.confirm("确定要删除吗？","if(value) smsTaskList.removeSelectedData()");
		    		 }else{
	 				 isc.say("请选择记录");
	 			 }
			}})
	    ]
	}),
    isc.ListGrid.create({//数据列表
		ID:"smsTaskList",dataSource:"sms_task",selectionType:"simple",selectionAppearance:"checkbox",
		fetchOperation:"myFetch",alternateRecordStyles:true,autoFetchData: true,
		showFilterEditor: true,filterOnKeypress: true,
		fields: [
			{name:"mt_dst_num"}, 
			{name:"mt_dst_name"},
			{name:"mt_content"},
			{name:"mt_at_time",width:110},
			{name:"mt_add_time",width:110}
		]
  })
]}]});
//已发列表
//---------------------------------------------------------------------
isc.SectionStack.create({ID:"sendedApp",width:'100%',sections:[{title:"已发送短信列表",autoShow:true, items:[
  isc.ListGrid.create({
		dataSource:"sms_send",
		fetchOperation:"myFetch",
		useAllDataSourceFields:false,
		alternateRecordStyles:true,
		autoFetchData: true,
		showFilterEditor: true,
		canRemoveRecords:false,
		selectionType:"simple",
		filterOnKeypress: true,
		fields: [
					{name:"mt_dst_num"}, 
					{name:"mt_dst_name"},
					{name:"mt_content"},
					{name:"mt_at_time"},
					{name:"mt_add_time"}
				]
})]}]});

//短信配制
//---------------------------------------------------------------------
isc.SectionStack.create({ID:"smConfigApp",width:'100%',sections:[{title:"短信模板配制",autoShow:true, items:[
	isc.HLayout.create({layoutTopMargin: 3,membersMargin: 3,height:30,
		members: [
		    isc.IButton.create({title: "增加",click:"smConfigList.startEditingNew()"}),
		    isc.IButton.create({title: "删除选中",click:function(){
				 if (smConfigList.getSelectedRecord()) {
	    			 isc.confirm("确定要删除吗？","if(value) smConfigList.removeSelectedData()");
	    		 }else{
    				 isc.say("请选择记录");
    			 }
			}})
	    ]
	}),
	 isc.ListGrid.create({
		ID:"smConfigList",dataSource:"sms_config",fetchOperation:"userFetch",addOperation:"userAdd",showRowNumbers:false,
		canEdit:true, modalEditing:true, autoFetchData: true, showFilterEditor: true,
		filterOnKeypress: true,	wrapCells: true,cellHeight: 56, selectionType:"simple",selectionAppearance:"checkbox",
		fields:[
				{name:"title"}, 
				{name:"content",showHover:true,
					cellChanged: function(record,value){
						record.mt_dst_size = Math.ceil(value.length/70);
						smConfigList.updateData(record);
					}	
				},
				{name:"mt_dst_size",canEdit:false},
				{name:"inCallSend"},
				{name:"outCallSend"}
		]
	})
]}]});



//彩信发送
//---------------------------------------------------------------------
isc.Window.create({//选择收件人窗口
  ID: "mmsWindow", title: "备选客户", width: '600', height: '400', autoCenter: true, immodal: true, showModalMask: true, autoDraw: false,
  items: [
		isc.ListGrid.create({
			ID:"mmSendListSrc",fetchOperation:"whiteFetch",dataSource:"customerDS",
			useAllDataSourceFields:true,alternateRecordStyles:true,autoFetchData: true,
		    showFilterEditor: true,selectionType:"simple",selectionAppearance:"checkbox",
			filterOnKeypress: true,dragDataAction: "copy",
			fields:[
			        {name:"category",hidden:true},
			        {name:"category_pk",optionDataSource:"customer_categoryDS",optionOperationId:"myFetch",valueField:"pk",displayField:"name" ,editorType: "SelectItem"}
		        ],
		    copyData:function(){
				  var ss = mmSendListSrc.getSelection();
				  for(var i = 0; i < ss.length; i++){
					 var s = ss.get(i);
					 var record = {mms_dst_num:s.telephone,mms_dst_name:s.truename};
					 if(!mmSendList.data.find("mms_dst_num",s.telephone)){
						 //只增加不重复的
						 mmSendList.addData(record);
					 }
				  }
		    }
		}),
		 isc.IButton.create({
			    title: "确定", click:function(){
			    	mmSendListSrc.copyData();
			    	mmsWindow.hide();
			    }
		 })
  ]
});
isc.HLayout.create({//布局
	membersMargin:10, height:'100%', width:"100%", ID:"mmSendApp",
	members:[
		isc.SectionStack.create({sections:[{title:"彩信发送",autoShow:true, items:[
	 	      	 isc.HLayout.create({layoutTopMargin: 3,membersMargin: 3,height:30,
		 	  	      members: [
		 	  	          isc.IButton.create({title: "增加收件人",click:"mmsWindow.show();mmSendListSrc.deselectAllRecords();"}),
		 	  	          isc.IButton.create({title: "删除选中收件人",click: "mmSendList.removeSelectedData();"})
		 	  	      ]
	 	      	 }),
           	   	 isc.TileGrid.create({
  					ID:"mmSendList",selectionType:"simple", tileWidth:80,border:0,tileHeight:35,height:100
  					,showEdges:false,border:1, data:[],emptyMessage:"aaaa",
           	   	    fields:[
							{name:"mms_dst_num"}, {name:"mms_dst_name"}
						]
           	   	 }),
			   	 isc.DynamicForm.create({
					ID: 'mmTaskForm',width: '700',titleAlign:"left",colWidths: [60,100,50,100,50,100],cellBorder:0,numCols:6,
					fields: [
						{name:"mms_sid", type:"text",title: "彩信模板",displayField:"mms_subject", editorType: "comboBox", addUnknownValues:false,
						 optionDataSource: "mms",optionOperationId:"allComMmsFetch",width:200,required:true,
						 changed:function(form,item,value){
								 if(value)
									 mmsShowPane.setContentsURL('mmsConfig.do?method=show&mmsSid='+value);
								 else
									 mmsShowPane.setContentsURL('');
							 }
						},
						{name:"mms_at_time", type:"datetime",title: "发送时间",canEdit:true},
						{name:"sign", type:"text",title: "彩信签名",canEdit:false,defaultValue:currUserSmsSign}
					]
				}),
				isc.IButton.create({title: "确定",width:'80'
					,click:function(){
						//将form中的数据设置到每条特发记录中
						var data = mmSendList.data;
						if(data.length < 1){
							isc.warn("请选择收件人！");
							return;
						}
						if(!mmTaskForm.validate()) return;
						
						//整理并发送
						var selectedRecord = mmTaskForm.getItem("mms_sid").getSelectedRecord();
						var wasQueuing = RPCManager.startQueue();
						for(var i = 0; i < data.length; i++){
							var d = data.get(i);
							d.mms_subject=selectedRecord.mms_subject;
							d.mms_size=selectedRecord.mms_size;
							d.mms_at_time=mmTaskForm.getValue('mms_at_time');
							mms_task.addData(d,null,{willHandleError:true});
						}
						if (!wasQueuing) RPCManager.sendQueue(function(responses){
							//清除数据
							mmSendList.setData([]);
							var errorMsg = " ";
							for(var i = 0;  i <  responses.getLength(); i++){
								var res = responses.get(i);
								if(res.status == -1){
									errorMsg += res.data+" ";
								}
							}
							if(errorMsg == " "){
								isc.say("已保存到待发列表中！");
							}else{
								isc.warn("短信条数超出配额限制，以下短信未能发送"+errorMsg);
							}
						});
					}
				}),
				isc.HTMLPane.create({
				    ID:"mmsShowPane",showEdges:false, contentsType:"page",width:'100%'
				})
	]}]})
		
]});



//彩信待发
//---------------------------------------------------------------------
isc.SectionStack.create({ID:"mmsTaskApp",width:'100%',sections:[{title:"待发送彩信列表",autoShow:true, items:[
	 isc.HLayout.create({//操作按钮
		layoutMargin: 3,height:30,
		members: [
		    isc.IButton.create({title: "删除选中",click:function(){
				 if (mmsTaskList.getSelectedRecord()) {
					 isc.confirm("确定要删除吗？","if(value) mmsTaskList.removeSelectedData()");
				 }else{
	 				 isc.say("请选择记录");
	 			 }
			}})
	    ]
	 }),
	 isc.ListGrid.create({
		ID:"mmsTaskList",dataSource:"mms_task",
		fetchOperation:"myFetch",
		alternateRecordStyles:true,
		autoFetchData: true,
		showFilterEditor: true,
		selectionType:"simple",
		filterOnKeypress: true,selectionType:"simple",selectionAppearance:"checkbox",
		fields: [
			{name:"mms_subject"}, 
			{name:"mms_size"},
			{name:"mms_dst_num",width:100},
			{name:"mms_at_time",width:100},
			{name:"create_date",width:100}
		]
	 })
]}]});
//彩信已发
//---------------------------------------------------------------------
isc.SectionStack.create({ID:"mmsSendApp",width:'100%',sections:[{title:"已发送彩信列表",autoShow:true, items:[
  isc.ListGrid.create({
		dataSource:"mms_send",
		fetchOperation:"myFetch",
		useAllDataSourceFields:false,
		alternateRecordStyles:true,
		autoFetchData: true,
		showFilterEditor: true,
		canRemoveRecords:false,
		selectionType:"simple",
		filterOnKeypress: true,
		fields: [
					{name:"mms_subject"}, 
					{name:"mms_size"},
					{name:"mms_dst_num",width:100},
					{name:"mms_at_time",width:100},
					{name:"create_date",width:100}
				]
})]}]});


//彩信配制
//---------------------------------------------------------------------
isc.Window.create({
    ID: "mmsConfigWindow", title: "彩信配制", width:'80%',height:'100%', autoCenter: true, isModal: true, showModalMask: true, autoDraw: false,
    closeClick : function () {
    	mmsConfigList.invalidateCache();
    	this.Super("closeClick", arguments);
    	this.animateMove(-3300);
    },
    items: [
		isc.HTMLPane.create({
		    ID:"mmsConfigPane",
		    showEdges:true,
		    contentsType:"page"
		})
    ]
});

isc.SectionStack.create({ID:"mmsConfigApp",width:'100%',
	sections:[{title:"彩信模板配制",autoShow:true, items:[
	  isc.HLayout.create({
	      autoDraw: false, layoutTopMargin: 3, membersMargin: 3, height:30,
	      members: [
	            isc.IButton.create({
	      		    title: "增加",
	      		    click:function(){
	      		    	mmsConfigPane.setContentsURL('mmsConfig.do?method=append');
	      		    	mmsConfigWindow.centerInPage();
	      		    	mmsConfigWindow.show();
	      		    }
	      	    }),
				isc.IButton.create({title: "删除选中",click:function(){
					 if (mmsConfigList.getSelectedRecord()) {
						 isc.confirm("确定要删除吗？","if(value) mmsConfigList.removeSelectedData()");
					 }else{
						 isc.say("请选择记录");
					 }
				}})
	      ]
	  }),
	  isc.ListGrid.create({
		ID:"mmsConfigList",selectionType:"simple",selectionAppearance:"checkbox",fetchOperation:"myMmsFetch",
		dataSource:"mms",useAllDataSourceFields:true,showRowNumbers:true,alternateRecordStyles:true,
	    autoFetchData: true, showFilterEditor: true,filterOnKeypress: true,wrapCells: true,
		fields:[
		   {name:"mms_subject",type:"link",target:"javascript"}
		   ,{name:"mms_size",width:50}
		   ,{name:"incoming_call_state",width:50}
		   ,{name:"outcoming_call_state",width:50}
		   ,{name:"create_date",width:100}
		],
	    cellClick:function (record, rowNum, colNum){
	    	if(colNum == 2){
	    		mmsConfigPane.setContentsURL('');
	    		mmsConfigPane.setContentsURL('mmsConfig.do?method=edit&mmsSid='+record.mms_sid);
	    		mmsConfigWindow.centerInPage();
	    		mmsConfigWindow.show();
	    	}
	    }
	})
]}]});




//内部短信
//---------------------------------------------------------------------
isc.HLayout.create({
	membersMargin:10, height:'100%', width:"100%", ID:"innerSmSendApp",
	members:[
	  isc.SectionStack.create({width:'40%',sections:[{title:"备选人员",autoShow:true, items:[
			isc.ListGrid.create({
				ID:"innerUserList",dataSource:"user",fetchOperation:"myComanyFetch",showRowNumbers:true,selectionAppearance:"checkbox",selectionType:"simple",
				height:"100%",autoFetchData: true,showFilterEditor: true,filterOnKeypress: true,dragDataAction: "copy",
				fields:[
						{name:"dep_pk",title:"部门",optionDataSource:"depDS",optionOperationId:"myComanyFetch",
							valueField:"pk",displayField:"name"
						}
						,{name:"truename"}
						,{name:"telephone",canEdit:"false",hidden:"true"}
				],
			    copyData:function(){
					  var ss = this.getSelection();
					  for(var i = 0; i < ss.length; i++){
						 var s = ss.get(i);
						 if(!innerSmSendList.data.find("telephone",s.telephone)){
							 //只增加不重复的
							 innerSmSendList.addData(s);
						 }
					  }
			    },
			    rowDoubleClick:function(s){
					 if(!innerSmSendList.data.find("telephone",s.telephone)){
						 //只增加不重复的
						 innerSmSendList.addData(s);
					 }
			    }
			})
	  ]}]}),
	  isc.VStack.create({width:32,align:"center",membersMargin:10,
		members:[
		      isc.Img.create({src:"arrow_right.png", width:32, height:32, 
				  click:"innerUserList.copyData()"
			  }),
			  isc.Img.create({src:"arrow_left.png", width:32, height:32,
				  click:"innerSmSendList.removeSelectedData()"
			  })
		]
	  }),
	  isc.SectionStack.create({width:'40%',sections:[{title:"收件人",autoShow:true, items:[
	   	  isc.ListGrid.create({
			ID:"innerSmSendList",selectionAppearance:"checkbox",selectionType:"simple",
			alternateRecordStyles:true,autoFetchData: true,filterOnKeypress: true,showRowNumbers:true,
			fields:[
				{name:"truename",title:"姓名"}
				,{name:"telephone",title:"电话"}
			],
		    rowDoubleClick:function(s){
				 this.removeData(s);
		    }
	  })]}]}), 
	  isc.SectionStack.create({width:'40%',sections:[{title:"短信内容",autoShow:true, items:[
		   	 isc.DynamicForm.create({
				ID:"innerSmSendForm",width: '100%',titleAlign:"left",colWidths: [70, "*"],
				fields: [
					{name:"mt_content",type:"textArea",showTitle: false,colSpan:'4',width:"*",required:"true",
						changed: function(form, item, value){
							form.getItem('mt_dst_size').setValue(Math.ceil(value.length/70));
						}
					}, 
					{name:"mt_dst_size", type:"integer",title: "短信条数",width:"*",canEdit:false,defaultValue:0} ,
					{name:"sign", type:"text",title: "签名",width:"*",canEdit:false,defaultValue:currUserSmsSign} ,
					{name:"mt_at_time", type:"datetime",title: "发送时间",canEdit:true	},
					{type:"button",title: "确定",width:'80'
						,click:function(){
							//将form中的数据设置到每条特发记录中
							var data = innerSmSendList.data;
							if(data.length < 1){
								isc.warn("请选择收件人！");
								return;
							}
							if(!innerSmSendForm.validate()) return;
							var wasQueuing = RPCManager.startQueue();
							for(var i = 0; i < data.length; i++){
								var d = data.get(i);
								var nd = {};
								nd.mt_content=innerSmSendForm.getValue('mt_content');
								nd.mt_at_time=innerSmSendForm.getValue('mt_at_time');
								nd.mt_dst_name=d.truename;
								nd.mt_dst_num=d.telephone;
								sms_task.addData(nd,null,{willHandleError:true});
							}
							if (!wasQueuing) RPCManager.sendQueue(function(responses){
								innerSmSendList.setData([]);//清除数据
								var errorMsg = " ";
								for(var i = 0;  i <  responses.getLength(); i++){
									var res = responses.get(i);
									if(res.status == -1){
										errorMsg += res.data+" ";
									}
								}
								if(errorMsg == " "){
									isc.say("已保存到待发列表中！");
								}else{
									isc.warn("短信条数超出配额限制，以下短信未能发送"+errorMsg);
								}
							});
						}
					}
				]
		   })
	  ]}]})
		
]});

//个人设置
//---------------------------------------------------------------------
isc.HLayout.create({
	membersMargin:10, height:'100%', width:"100%", ID:"changePasswordApp",
	members:[
		isc.SectionStack.create({width:'100%',sections:[{title:"修改密码",autoShow:true, items:[
			isc.DynamicForm.create({
			    ID:"cpwForm",saveOperationType:"update",dataSource:"user",
			    fields: [
			        {name: "oldPassword", title: "旧密码", required: true, type: "password"	},
			        {name: "password", title: "新密码", required: true, type: "password",
			        	validators: [{type: "matchesField",otherField: "password2",
			        		errorMessage: "两次密码输入不一致"
			        	}]
			        },
			        {name: "password2",required: true,title: "新密码确认",type: "password"},
			        {title: "提交",type: "button",width:80,
			         click: function(){
			        	 cpwForm.saveData(function(dsResponse, data, dsRequest){
			        		 if(dsResponse.status < 0){
			        			 isc.warn(dsResponse.errors);
			        		 }else{
			        			 isc.say("密码修改成功");
			        			 cpwForm.clearValues();
			        		 }
			        	 },{operationId: "changePassword"});
			         }
			        }
			    ]
			})
		]}]}),
		isc.SectionStack.create({width:'100%',sections:[{title:"挂机短彩信发送间隔设置",autoShow:true, items:[
			isc.DynamicForm.create({
			    ID:"smIntervalForm",saveOperationType:"update",dataSource:"user",
			    fields: [
			        {name: "pk",defaultValue:currUserPK,type:"hidden"},
			        {name: "smInterval",title:"间隔",value:currUserSmInterval,  editorType: "comboBox",required:true,defaultValue:0},
			        {type: "StaticTextItem",value:"默认每次挂机均发，可直接输入小时数。"},
			        {title: "提交",type: "button",width:80,
			         click: function(){
			        	 smIntervalForm.saveData(function(dsResponse, data, dsRequest){
			        		 if(dsResponse.status < 0){
			        			 isc.warn(dsResponse.errors);
			        		 }else{
			        			 isc.say("挂机短彩信发送间隔设置成功");
			        			 var v = smIntervalForm.getValue("smInterval");
			        			 if(v == null) v ="";
			        			 smIntervalForm.reset();
			        			 
			        			 smIntervalForm.setValue("smInterval",v);
			        		 }
			        	 });
			         }
			        }
			    ]
			})
		]}]})
]});

//通信记录
//---------------------------------------------------------------------
isc.SectionStack.create({ID:"callinApp",width:'100%',sections:[{title:"通话记录查询",autoShow:true, items:[
isc.ListGrid.create({//通话记录列表
	dataSource:"callinDS",fetchOperation:"customerFetch",
	useAllDataSourceFields:true,
	showRowNumbers:true,
	canEdit:false,
	modalEditing:true,
	alternateRecordStyles:true,
	autoFetchData: true,
	showFilterEditor: true,
	filterOnKeypress: true
})
]}]});


